/**
 * Created by Lcp on 2018/3/14.
 */
var inputTimeBegin = '',//开始时间
    inputTimeEnd = '',//结束时间
    data = [];
laydate.render({
    elem: '#date', //指定元素
    showBottom:true,
    range: '~',
    max: 0,
    done: function(value, date, endDate){
        if(value.length > 0){
            inputTimeBegin = value.split('~')[0] + ' 00:00:00';
            inputTimeEnd = value.split('~')[1] + ' 23:59:59';
        }else{
            inputTimeBegin = '';
            inputTimeEnd = '';
        }
    }
});
$('tbody').css({height: $(window).height() - 250 + 'px'});
//列表
function searchResult(pageIndex){
    $.ajax({
        type: 'get',
        url: baseUrls + 'faceResult',
        data: {
            inputTimeBegin: inputTimeBegin,
            inputTimeEnd: inputTimeEnd,
            pageSize: 10,
            pageIndex: pageIndex
        },
        beforeSend: function(){
            Loading();
        },
        success: function(response){
            closeLoading();
            $('tbody').html('');
            if(response.responseCode == '1000'){
                if(response.content.list.length > 0){
                    data = response.content.list;
                    sessionStorage.setItem('data',JSON.stringify(data));
                    for(var i = 0; i < data.length; i++){
                        $('tbody').append(`
                                 <tr onclick="showDetail(${i})">
                                    <td>${data[i].xh != null ? data[i].xh : '无'}</td>
                                    <td>${data[i].name != null ? data[i].name : '无'}</td>
                                    <td>${data[i].idcard != null ? data[i].idcard : '无'}</td>
                                    <td>${data[i].type != null ? data[i].type : '无'}</td>
                                    <td>${data[i].personateName != null ? data[i].personateName : '无'}</td>
                                    <td>${data[i].personateIdcard != null ? data[i].personateIdcard : '无'}</td>
                                    <td>${data[i].capturedTime != null ? data[i].capturedTime : '无'}</td>
                                    <td>${data[i].solveCaseNum != null ? data[i].solveCaseNum : '无'}</td>
                                    <td>${data[i].caseNum != null ? data[i].caseNum : '无'}</td>
                                    <td>${data[i].caseType != null ? data[i].caseType : '无'}</td>
                                    <td>${data[i].comments != null ? data[i].comments : '无'}</td>
                                 </tr>`)
                    }
                    $('#demo_pag1').bs_pagination({
                        totalPages: response.content.pages,
                        visiblePageLinks: 6,
                        currentPage: response.content.pageNum,
                        showGoToPage: false,
                        showRowsPerPage: false,
                        showRowsInfo: false,
                        showRowsDefaultInfo: false,
                        navListContainerClass: 'col-xs-12',
                        onChangePage: function (event, data) {
                            searchResult(data.currentPage);
                        }
                    })
                }
            }else{
                Msg();
            }
        },
        error: function(){
            closeLoading();
        }
    })
}
searchResult(1);
//展示详情
function showDetail(item){
    layer.open({
        type: 2,
        title: `详情：${data[item].name != null ? data[item].name : ''}`,
        shadeClose: true,
        shade: 0.8,
        area: ['80%', '80%'],
        offset: 'auto',
        content: `fileImg/detail.html?index=${item}`
    });
}
//导出
function excel(item) {
    window.location.href = `${baseUrls}resultExcel?excelFlag=${item}&inputTimeBegin=${inputTimeBegin}&inputTimeEnd=${inputTimeEnd}`;
}